<!-- 
  @name: 优惠券详情
  @date: 2020.3.12
 -->
<template>
	<view class="content">
		<!-- 优惠券卡片 -->
		<view class="ticket">
			<view class="card">
				<view class="topview">
					<view class="left">
						<view class="title">
							<text v-if="info.couponOrderAmount2 == 0">{{info.couponAmount}}元无门槛优惠券</text>
							<text v-else>加注金额满{{info.couponOrderAmount}}元可使用</text>
						</view>
						<view class="preview" v-if="info.couponStatus === 2">
							{{info.useBeginTime}}<text class="str">即将开始</text>
						</view>
					</view>
					<view class="right" :class="info.couponStatus === 3 ? 'not' : ''">
						<text class="icon">￥</text>
						<text class="num">{{info.couponAmount}}</text>
					</view>
				</view>
				<view class="btmview">
					<view class="left">有效期{{info.useBeginTime}}至{{info.useEndTime}}</view>
				</view>
				<view class="notimg" v-if="info.couponStatus === 3"></view>
			</view>
		</view>
		
		<!-- 更多信息 -->
		<view class="details">
			<view class="item"><view class="left">优惠券名称</view><view class="right">{{info.couponName}}</view></view>
			<view class="item"><view class="left">面值（元）</view><view class="right">{{info.couponAmount}}</view></view>
			<view class="item"><view class="left">发行总量（张）</view><view class="right">{{info.dispatchNum}}</view></view>
			<view class="item"><view class="left">发布时间</view><view class="right">{{info.releaseTime}}</view></view>
			<view class="item"><view class="left">开始时间</view><view class="right">{{info.useBeginTime}}</view></view>
			<view class="item"><view class="left">结束时间</view><view class="right">{{info.useEndTime}}</view></view>
			<view class="item">
				<view class="left">使用门槛</view><view class="right">
					<text v-if="info.couponOrderAmount2 == 0">无使用门槛</text>
					<text v-else>用户加注满{{info.couponOrderAmount}}使用</text>
				</view>
			</view>
			<view class="item"><view class="left">领取数量（张）</view><view class="right">{{info.takeNum}}</view></view>
			<view class="item bn"><view class="left">使用数量（张）</view><view class="right">{{info.useNum}}</view></view>
		</view>
		
		<!-- 按钮 -->
		<view class="btn_pub delete" @tap="stopTk" v-show="!stop">
			<text>终止推送</text>
			<text class="t1">（被领取的仍生效）</text>
		</view>
		<view class="btn_pub stop" v-show="stop">
			<text>已终止推送</text>
			<text class="t1">（被领取的仍生效）</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				couponId: '',  //优惠券id
				info: {},  //信息
				stop: false,  //是否被终止
			}
		},
		onLoad(e) {
			this.couponId = e.couponId;
			this.getInfo();
		},
		onShow() {
			if(this.$store.state.reLogin) {
				this.getInfo();
				this.$store.commit('hasLogin');
			}
		},
		methods: {
			//获取信息
			getInfo() {
				this.$http({
					url: this.$api.couponUrl + 'getcoupondetail',
					data: {
						couponId: this.couponId
					}
				}).then(res => {
					this.info = res;
					this.info.couponOrderAmount2 = parseFloat(res.couponOrderAmount);
					this.stop = this.info.dispatchStatus === 0 ? true : false;
				});
			},
			//终止推送
			stopTk() {
				uni.showModal({
					content: '确认终止推送吗？',
					success: (rs) => {
						if(rs.confirm) {
							this.$http({
								url: this.$api.couponUrl + 'stoppush',
								data: {
									couponId: this.couponId
								}
							}).then(res => {
								this.$successToast('已终止！');
								this.stop = true;
							});
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	/* 优惠券卡片 */
	.ticket {
		width: 750rpx;
		height: 260rpx;
		background-color: $color-white;
		.card {
			position: relative;
			width: 690rpx;
			margin: 30rpx;
			padding-top: 40rpx;
			padding-bottom: 25rpx;
			box-shadow: $box-shadow;
			background-color: $color-white;
			border-radius: $border-radius-bm;
			.topview,
			.btmview {
				width: 100%;
				display: flex;
				flex-direction: row;
				.left {
					width: 420rpx;
				}
				.right {
					flex: 1;
					color: $color-primary;
					display: flex;
					flex-direction: row;
					justify-content: center;
				}
				.right.not {
					color: $color-grey;
				}
			}
			.topview {
				height: 110rpx;
				.left {
					margin-left: 15rpx;
					padding-left: 26rpx;
					border-bottom: 1rpx solid $color-list;
					.title {
						font-size: 32rpx;
					}
					.preview {
						margin-top: 20rpx;
						font-size: 20rpx;
						color: $color-grey;
						font-family: $font-family-num;
						.str {
							color: #FCAB04;
							margin-left: 8rpx;
						}
					}
				}
				.right {
					align-items: flex-end;
					padding-bottom: 10rpx;
					.icon {
						font-size: 24rpx;
						font-weight: 500;
						padding-bottom: 9rpx;
					}
					.num {
						font-size: 50rpx;
						font-family: $font-family-num;
					}
				}
			}
			.btmview {
				margin-top: 20rpx;
				align-items: center;
				.left {
					padding-left: 40rpx;
					font-size: 20rpx;
					color: $color-grey;
				}
			}
		}
		.notimg {
			position: absolute;
			top: 46rpx;
			left: 350rpx;
			width: 140rpx;
			height: 140rpx;
			background-image: url('http://img.etubang.com/group1/M00/00/42/rBCky15pqx-AVHUZAABUq78hxaE730.png');
		}
	}
	
	/* 更多信息 */
	.details {
		width: 100%;
		padding: 0 40rpx;
		background-color: $color-white;
		.item {
			width: 100%;
			height: 100rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			border-bottom: 1rpx solid $color-list;
			.left {
				width: 360rpx;
				color: $color-grey-dark;
			}
			.right {
				flex: 1;
				font-family: $font-family-num;
			}
		}
		.item.bn {
			border-bottom: none;
		}
	}
	
	/* 按钮 */
	.btn_pub {
		margin-top: 40rpx;
		.t1 {
			font-size: 20rpx;
		}
	}
	.btn_pub.stop {
		color: $color-grey;
	}
	
</style>
